<?php 
$txt1 = '';
$txt2 = '';
if ($edit == 0){
$txt1 = 'Dscto';
$txt2 = 'Costes';
}
else {
$txt1 = 'Costes';
$txt2 = 'Monto';
}
?>

	<table style="margin-bottom:5px;" width="100%" border="1" rules="all" cellspacing="0" cellpadding="0" class="tableIn">
		<thead>
	  <tr>
	  <th></th>
		<th>Almacen</th>
		<th>Articulo</th>
		<th>Descripcion</th>
		<th>Precio</th>
		<th>PVP.UN</th>
		<th>Cantidad</th>
		<th><?php echo $txt1; ?></th>
		<th><?php echo $txt2; ?></th>
        <?php 
		if ($edit == 0){
		?>
		<th>Neto</th>
		<th>IVA</th>
        <?php 
		}
		else {
		?>
		<th>IVA</th>        
        <?php 
		}
		
        ?>
	  </tr>
	  </thead>
	  <tbody>
	  <?php 
	  $subt = 0;
	  $subt_igv = 0;
	  $tot = 0;
	  if (trim($factura) != '')  {
	  $sql  = "call sp_getFacturaDet('".$factura."')";
	  $res2 = $mysqli->query($sql) or die($mysqli->error.__LINE__);
	  if ($res2){
		while($row = $res2->fetch_assoc()){		
		$pvu = myRound(($row['DetFactNet']+$row['DetFactIva'])/$row['DetFacQty']);	
		$subt += $row['DetFactNet'];		
		$subt_igv += $row['DetFactIva'];
		$alm = $row['AlmacenID'];
	  ?>
	  <tr title="Item&nbsp;<?php echo $row['DetFacPos']; ?>">
	  <td>
      <?php 
	  if ($row['DetFactQtt']>0){
		?>
      <input type="checkbox" class="clsChkNC" onchange="calcNetNC(null)" checked/>
      <?php 
	  }
	  else {
	  ?>
      &nbsp;&nbsp;
      <?php 
	  }
      ?>      </td>
	   <td><select disabled="disabled"><?php echo str_replace("value='".$alm."'","value='".$alm."' selected='selected'",$combo);   ?></select></td>
		<td><?php echo $row['ArticuloID'];?></td>
	   <td><?php echo $row['DetFactTxt'];?></td>
       
       <?php 
	   if ($edit == 0){
	   ?>
<td class="qt clsNcPru"><?php echo $row['DetFactPru'];?></td>
<td class="qt clsNcPvu"><?php echo $pvu;?></td>
<td class="qt ">
<input tabindex="text" class="qt clsNcQty" onchange="mr(this);calcNetNC(this);" value="<?php echo $row['DetFactQtt'];?>" />
<?php ?></td>
<td class="qt clsNcPdc"><?php echo $row['DetFactPdt'];?></td>
<td class="qt"><?php echo $row['DetFactCst'];?></td>
<td class="qt clsNcImp"><?php echo $row['DetFactNet'];?></td>
<td class="qt clsNcIva"><?php echo $row['DetFactIva'];?></td>
        <?php 
		}
		else {
		?>
<td class="qt clsNcPru"> <?php echo $row['DetFactPru'];?></td>
<td class="qt clsNcQty"><?php echo $row['DetFactQtt'];?></td>
<!-- <td><?php /*echo $row['DetFactDct'];*/ echo "0.00"; ?></td> -->
<td class="qt"><?php echo $row['DetFactCst'];?></td>
<td class="qt">
	<?php if ($row['DetFactQtt']>0){ 
	$new_mon = myRound(( $row['DetFactPru'] * ( 1 - ( 0.01 * $row['DetFactPdt']))) * $row['DetFactQtt']);
	?>
<input type="text" class="qt clsNcImp" onchange="mr(this);calcNetNC(this);" value="<?php echo $new_mon; /* $row['DetFactNet']; */?>" />
<?php 
}
else {
?>
<span class="clsNcImp">
<?php 
echo $row['DetFactNet'];
} ?>
</span></td>
<td class="clsNcIva qt"><?php echo $row['DetFactIva'];?></td>
<!-- <td class="clsNcNet"><?php echo $row['DetFactIva']+$row['DetFactNet'];?></td> -->
<?php 
		}
		?>        
	  </tr>
	
	  <?php 
		}
		$tot = $subt + $subt_igv;
		$res2->close();
		$mysqli->check_result();
	  }
	  }
	  ?>
	  </tbody>
	  <tfoot>
	  </tfoot>
	</table>
<script type="text/javascript">
	calcNetNC();
	</script>